#ifndef _NNSLITE_HEAP_FILE_H_
#define _NNSLITE_HEAP_FILE_H_

#include "nnsliteglobal.h"

struct nnsliteHeapFS;

struct nnsliteHeapPageHeader
{
	u32 usedSize;
	u32 state;
};

typedef struct nnsliteHeapPageHeader nnsliteHeapPageHeader;

struct nnsliteHeapFile
{
	u32 fileNo;
	u32 startPageIndex;
	u32 lastPageIndex;
	u64 length;
	u64 capacity;
	u8  isUsed;
	struct nnsliteHeapFS* heapFS;
};

typedef struct nnsliteHeapFile nnsliteHeapFile;

struct nnsliteHeapFS
{
	char filename[NNSLITE_MAX_NAMELEN];
	FILE* fp;
	u32  pageSize;
	u32  numPages;
	u64  pageStoreOffset;
	nnsliteHeapPageHeader* pageAllocationTable;
	nnsliteHeapFile files[NNSLITE_MAX_NUM_DATAPAGE];
};

typedef struct nnsliteHeapFS nnsliteHeapFS;

NNSLITE_RET nnsliteHeapFSInit(nnsliteHeapFS* heapFS, const char* filename, u32 pagesize, u32 numpages);
NNSLITE_RET nnsliteHeapFSFree(nnsliteHeapFS* heapFS);

NNSLITE_RET nnsliteHeapFileOpenNew(nnsliteHeapFS* heapFS, nnsliteHeapFile** heapFile);
NNSLITE_RET nnsliteHeapFileOpen(nnsliteHeapFS* heapFS, u32 fileNo, nnsliteHeapFile** heapFile);
NNSLITE_RET nnsliteHeapFileClose(nnsliteHeapFile* heapFile);
NNSLITE_RET nnsliteHeapFileWrite(nnsliteHeapFile* heapFile, const void* buf, u64 size);
NNSLITE_RET nnsliteHeapFileRead(nnsliteHeapFile* heapFile, void* buf, u64 offset, u64 size);

#endif
